package com.version1_4.dao.implement;

import com.version1_4.dao.ActivityDao1_4;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by reeveslee on 16/5/22.
 */
@Repository
public class ActivityDaoImpl1_4 implements ActivityDao1_4 {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<Map<String, Object>> getActivityInfoByType(int activityType) {
        String sql = "SELECT link,text AS activityTitle,image AS activityTitleImage FROM activity_banner ORDER BY orders ASC";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public String activityInfo(int activityId) {
        String sql = "SELECT html FROM activity WHERE activityID=?";
        try {
            return jdbcTemplate.queryForObject(sql, new Object[]{activityId}, java.lang.String.class);
        } catch (EmptyResultDataAccessException e) {
            return "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>跬步+活动</title></head><body></body></html>";
        }
    }
}
